<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<title>Mouse Shadow</title>
		<link
			rel="icon"
			href="https://fav.farm/🔥" />
	</head>
	<body>
		<div class="hero">
			<h1 contenteditable>🔥WOAH!</h1>
		</div>

		<style>
			html {
				color: black;
				font-family: sans-serif;
			}

			body {
				margin: 0;
			}

			.hero {
				min-height: 100vh;
				display: flex;
				justify-content: center;
				align-items: center;
				color: black;
			}

			h1 {
				text-shadow: 10px 10px 0 rgba(0, 0, 0, 1);
				font-size: 100px;
			}
		</style>

		<script
			async
			type="module">
			let hero = document.querySelector('.hero');
			let text = document.querySelector('h1');
			let walk = 100; // 这是用来控制文字的阴影的移动距离

			hero.addEventListener('mousemove', function (e) {
				let { offsetWidth, offsetHeight } = hero;
				let { offsetX, offsetY } = e;
				let xWalk = Math.round((offsetX / offsetWidth) * walk - walk / 2);

				let yWalk = Math.round((offsetY / offsetHeight) * walk - walk / 2);

				text.style.textShadow = `
      ${xWalk}px ${yWalk}px 0 rgba(255,0,255,0.7),
      ${xWalk * -1}px ${yWalk}px 0 rgba(0,255,255,0.7),
      ${yWalk}px ${xWalk * -1}px 0 rgba(0,255,0,0.7),
      ${yWalk * -1}px ${xWalk}px 0 rgba(0,0,255,0.7)
    `;
			});
		</script>
	</body>
</html>
